unit FileOperations;

interface
uses
  Classes, uMatrix;

type

  TFileOperator = class

    class procedure CSVToVector (Line : string; M : TMatrix; Delimiter : string = ';');
    class function  ListFiles(Path : string; Mask  : string = '*.*') : TStringList;

  end;

implementation

uses SysUtils;

{ TFileOperator }

class procedure TFileOperator.CSVToVector(Line: string; M: TMatrix; Delimiter : string = ';');
var
  LineStringList : TStringList;
  i : Integer;

begin

  LineStringList := TStringList.Create;

  LineStringList.Delimiter := Delimiter[1];

  LineStringList.DelimitedText := Line;

  for i:= 0 to LineStringList.Count-1 do
    begin
      if LineStringList[i] <> '' then
        M[i, 0] := StrToFloat(LineStringList[i])
    end;

  FreeAndNil(LineStringList);

end;

class function TFileOperator.ListFiles(Path : string; Mask  : string = '*.*') : TStringList;
var
   Dir      : TSearchRec ;
   FileEnd  : Boolean ;
   List     : TStringList ;
begin

   List    := TStringList.Create ;

   Path := IncludeTrailingBackslash(Path);

   FileEnd := ( FindFirst ( Path + Mask, faAnyFile  , Dir ) <> 0 ) ;

   while not FileEnd do
   begin

      List.Add ( Dir.Name ) ;

      FileEnd := ( FindNext ( Dir ) <> 0 ) ;
   end;
   result := List ;
end;

end.
